﻿using System;
using System.Text;

namespace Little.Soldier.SWIFT
{
  [Serializable]
  public class SwiftTag
  {
    private const long _SerialVersionUID = 1L;
    private string _Name;
    private UnparsedTextList _UnparsedTexts;
    private string _Value;

    public virtual string LetterOption
    {
      get
      {
        switch (this.Name)
        {
          case null:
            return (string) null;
          default:
            StringBuilder stringBuilder = new StringBuilder();
            for (int index = 0; index < this.Name.Length; ++index)
            {
              char c = this.Name[index];
              if (char.IsLetter(c))
                stringBuilder.Append(c);
            }
            if (stringBuilder.Length > 0)
              return ((object) stringBuilder).ToString();
            else
              goto case null;
        }
      }
    }

    public virtual string Name
    {
      get
      {
        return this._Name;
      }
      set
      {
        this._Name = value;
      }
    }

    public virtual int NameAsInt
    {
      get
      {
        switch (this.Name)
        {
          case null:
            return -1;
          default:
            StringBuilder stringBuilder = new StringBuilder();
            for (int index = 0; index < this.Name.Length; ++index)
            {
              char c = this.Name[index];
              if (char.IsNumber(c))
                stringBuilder.Append(c);
              else
                break;
            }
            if (stringBuilder.Length > 0)
              return int.Parse(((object) stringBuilder).ToString());
            else
              goto case null;
        }
      }
    }

    internal virtual UnparsedTextList UnparsedTexts
    {
      get
      {
        this.U008EU0002();
        return this._UnparsedTexts;
      }
      set
      {
        this._UnparsedTexts = value;
      }
    }

    internal virtual int UnparsedTextsSize
    {
      get
      {
        if (this._UnparsedTexts == null)
          return 0;
        else
          return this._UnparsedTexts.Size;
      }
    }

    public virtual string Value
    {
      get
      {
        return this._Value;
      }
      set
      {
        this._Value = value;
      }
    }

    public SwiftTag()
    {
      this.UnparsedTexts = (UnparsedTextList) null;
    }

    internal SwiftTag(UnparsedTextList unparsedText)
      : this()
    {
      this.UnparsedTexts = unparsedText;
    }

    public SwiftTag(string inner)
    {
      this.UnparsedTexts = (UnparsedTextList) null;
      int length = inner.IndexOf(':');
      if (length >= 0)
      {
        if (length > 0)
          this.Name = inner.Substring(0, length);
        if (length + 1 >= inner.Length)
          return;
        this.Value = inner.Substring(length + 1);
      }
      else
      {
        if (inner.Length <= 0)
          return;
        this.Value = inner;
      }
    }

    internal SwiftTag(string inner, UnparsedTextList unparsedText)
      : this(inner)
    {
      this.UnparsedTexts = unparsedText;
    }

    public SwiftTag(string tagname, string value)
    {
      this._UnparsedTexts = (UnparsedTextList) null;
      this.Name = tagname;
      this.Value = value;
    }

    internal SwiftTag(string tagname, string value, UnparsedTextList unparsedText)
      : this(tagname, value)
    {
      this.UnparsedTexts = unparsedText;
    }

    public override bool Equals(object obj)
    {
      if (this != obj)
        goto label_18;
label_17:
      return true;
label_18:
      if (obj == null || this.GetType() != obj.GetType())
        return false;
      SwiftTag swiftTag = (SwiftTag) obj;
      if (this.Name == null)
      {
        if (swiftTag.Name != null)
          return false;
      }
      else if (this.Name != swiftTag.Name)
        return false;
      if (this.UnparsedTexts == null)
      {
        if (swiftTag.UnparsedTexts != null)
          return false;
      }
      else if (!this.UnparsedTexts.Equals((object) swiftTag.UnparsedTexts))
        return false;
      if (this.Value == null)
      {
        if (swiftTag.Value != null)
          return false;
        else
          goto label_17;
      }
      else if (this.Value != swiftTag.Value || !object.ReferenceEquals((object) this, (object) swiftTag))
        return false;
      else
        goto label_17;
    }

    public override int GetHashCode()
    {
      return 31 * (31 * (31 * 1 + (this.Name != null ? this.Name.GetHashCode() : 0)) + (this.UnparsedTexts != null ? this.UnparsedTexts.GetHashCode() : 0)) + (this.Value != null ? this.Value.GetHashCode() : 0);
    }

    public virtual bool IsNumber(int i)
    {
      switch (this.Name)
      {
        case null:
          return false;
        default:
          return this.Name.StartsWith(string.Concat((object) i));
      }
    }

    internal virtual void U0084(SwiftMessage message)
    {
      this.U008EU0002();
      this.UnparsedTexts.AddTex(message);
    }

    internal virtual void U0084(string text)
    {
      this.U008EU0002();
      this.UnparsedTexts.AddTex(text);
    }

    internal virtual SwiftMessage U0086(int index)
    {
      this.U008EU0002();
      return this.UnparsedTexts.U0083U0003(index);
    }

    internal virtual string U0087(int index)
    {
      this.U008EU0002();
      return this.UnparsedTexts.U0082U0003(index);
    }

    internal virtual bool U0088(int index)
    {
      this.U008EU0002();
      return this.UnparsedTexts.U0084U0003(index);
    }

    internal virtual void U008EU0002()
    {
      if (this._UnparsedTexts != null)
        return;
      this._UnparsedTexts = new UnparsedTextList();
    }

    public override string ToString()
    {
      return this._Name;
    }
  }
}
